﻿using System;
using System.ComponentModel;
using Windows.UI;
using Windows.UI.Text;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace com.IronOne.BoardPACWinApp.View.UserControl
{
    public sealed partial class CalendarItemUserControl
    {
        private Style _gridStyle;
        //NOTE: https://winstoreappcalendar.codeplex.com/downloads/get/691256
        public CalendarItemUserControl()
        {
            InitializeComponent();
        }

        public CalendarItemUserControl(DateTime value, string text) : this()
        {
            Value = value;
            Text = text;
        }

        public CalendarItemUserControl(DateTime value, string text, Style style) : this(value, text)
        {
            GridStyle = style;
        }

        public DateTime Value { get; set; }
        public string Text { get; set; }

        public Style GridStyle
        {
            get { return _gridStyle; }
            set
            {
                _gridStyle = value;

                PropertyChangedEventHandler handler = PropertyChanged;
                handler(this, new PropertyChangedEventArgs("GridStyle"));
            }
        }

        private void PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            ItemBox.Style = GridStyle;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            ItemValue.Text = Text;
            ItemBox.Style = GridStyle;

            if (Value.CompareTo(DateTime.Today) == 0 && !String.IsNullOrEmpty(ItemValue.Text))
            {
                ItemBox.Background = new SolidColorBrush(Colors.DarkOrange);
                ItemValue.FontWeight = FontWeights.Bold;
                ItemValue.Foreground = new SolidColorBrush(Colors.Black);
            }
        }
    }
}